<template>
  <div :class="className" :style="{height:height,width:width}" />
</template>

<script>
import echarts from 'echarts'
require('echarts/theme/macarons') // echarts theme
import resize from './mixins/resize'
import {detectTypeInfo} from "@/api/system/historyInfo";

export default {
  mixins: [resize],
  props: {
    info:{
      type:Object,
      default:{'title.text':'检测类别统计','tooltip.trigger':'检测类别'},
    },
    className: {
      type: String,
      default: 'chart'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '300px'
    }
  },
  data() {
    return {
      chart: null,
      datainfo:[
        {value: 0, name: '变化检测'},
        {value: 0, name: '目标提取'},
        {value: 0, name: '目标检测'},
        {value: 0, name: '地物分类'},
        {value: 0, name: '车辆检测'},
        {value: 0, name: '语义分割'},
        {value: 0, name: '场景分类'}]
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.initChart()
    })
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  methods: {

    initChart() {
      detectTypeInfo().then(res=>{
        console.log(res)
        let info=[{value: res.data['变化检测'], name: '变化检测'}, {value: res.data['目标提取'], name: '目标提取'},
          {value: res.data['目标检测'], name: '目标检测'}, {value: res.data['地物分类'], name: '地物分类'},
          {value: res.data['车辆检测'], name: '车辆检测'}, {value: res.data['语义分割'], name: '语义分割'},
          {value: res.data['场景分类'], name: '场景分类'}]
        this.datainfo=info
        // 初始化earchs
        this.chart = echarts.init(this.$el, 'macarons')
        this.chart.setOption({
          title: {
            text: this.info['title.text'],
            left: 'center'
          },
          tooltip: {
            trigger: 'item',
            formatter: '{a} <br/>{b} : {c} ({d}%)'
          },
          legend: {
            orient: 'vertical',
            left: 'left'
          },

          series: [
            {
              name: '类别',
              type: 'pie',
              data: this.datainfo,
              emphasis: {
                itemStyle: {
                  shadowBlur: 10,
                  shadowOffsetX: 0,
                  shadowColor: 'rgba(0, 0, 0, 0.5)'
                }
              }
            }
          ]
        })
      })

    }
  }
}
</script>
